package com.geyue.controller;

import com.geyue.common.toolbox.result.Res;
import com.geyue.common.util.StrUtils;
import com.geyue.core.model.Student;
import com.geyue.core.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Lyon on 2017/4/20.
 */
@RestController
@RequestMapping("/api/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public Object login(String tel,String password){

        if(StrUtils.isEmpty(tel) || StrUtils.isEmpty(password))
            return Res.fail("Access interface param is empty!");

        Student student = new Student();
        student.setTel(tel);
        student = studentService.getOne(student);

        if(student == null)
            return Res.fail("User is not exist!");
        else if(!password.equals(student.getPassword()))
            return Res.fail("Username or password incorrect");

        return Res.success("Login success!",student);
    }

    @RequestMapping(value = "/all",method = RequestMethod.GET)
    public Object all(){
        return studentService.all();
    }
}
